layui.config({
    base: "static/layui/"
}).extend({
    tableSelect: 'tableSelect'
}).use(['form', 'layer', 'jquery', 'table', 'laydate', 'upload','tableSelect'], function () {
    var table = layui.table;
    var laydate = layui.laydate;
    var form = layui.form;
    var tableSelect = layui.tableSelect;

    tableSelect.render({
        elem: '#material',
        checkedKey: 'djMaterial',
        searchPlaceholder: '料号',
        searchKey: 'djMaterial',
        table: {
            url: 'base_material/selectTableList'
            ,method: 'post'
            ,cols: [
                [
                    { type: 'radio' },
                    { field: 'djMaterial', title: '料号' },
                    { field: 'materialMrk', title: '料号描述' },
                    { field: 'className', title: '料号类别' }
                ]
            ]
        },
        done: function (elem, data) {
            var NEWJSON = []
            //单选只有一条数据
            let d = data.data[0];
            elem.val(d.djMaterial)
            $('#strGoodsName').val(d.materialMrk)
        }
    })
})

function getFormDataAndValidate(){
    var flag = $("#form").form('enableValidation').form('validate');
    if(!flag){
        return [false,{}];
    }
    var data = $('#form').serializeArray();
    var obj = new Object();
    $.each(data, function(index, e){
        obj[e.name] = e.value;
    })
    //计算良率
    let sum = Number.parseInt(obj.nonDefective) + Number.parseInt(obj.defectiveProducts);
    let percentage = (sum / (sum + Number.parseInt(obj.defectiveProducts))) * 100;
    obj.percentage = percentage.toFixed(2);
    return [true,obj];
}